from django.db import models
from utils.choices import *  # 类型选择
import uuid


# Create your models here.
# 用户金币表
class Gold(models.Model):
    id = models.CharField(max_length=50, primary_key=True)  # ID
    money = models.IntegerField(default=0)  # 金币数量
    transaction_date = models.DateTimeField(auto_now_add=True)  # 交易日期和时间，自动设置为记录创建的时间


class NavButton(models.Model):
    iconPath = models.URLField(max_length=600)  # 图标地址
    title = models.CharField(max_length=600)  # 图标标题
    route = models.CharField(max_length=100, default="")  # 图标路由
    pageStatus = models.CharField(max_length=100, default="")  # 图标状态


# 红娘信息表
class Matchmaker(models.Model):
    nickname = models.CharField(max_length=30, blank=True)  # 红娘昵称
    url = models.CharField(max_length=300, blank=True)  # 红娘头像地址
    wxUrl = models.CharField(max_length=300, blank=True)  # 微信头像地址
    position = models.CharField(max_length=20, blank=True)  # 红娘职位
    id = models.CharField(max_length=100, primary_key=True)  # 红娘唯一标识ID
    phone = models.CharField(max_length=12, blank=True)  # 红娘电话
    come_from = models.CharField(max_length=30, blank=True)  # 红娘属店
    job_number = models.CharField(max_length=10, blank=True)  # 工号


# 轮播图模型
class Banner(models.Model):
    imgUrl = models.URLField(max_length=255)
    hrefUrl = models.URLField(max_length=255)
    type = models.CharField(max_length=50)


class UserProfile(models.Model):
    # id
    id = models.CharField(primary_key=True, default=uuid.uuid4, editable=False, max_length=100)
    # 头像
    avatar = models.CharField(max_length=600, blank=True, verbose_name="头像")  # 用户头像字段
    # 性别
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES, verbose_name="性别", blank=True)
    # 年龄
    age = models.PositiveIntegerField(verbose_name="年龄", blank=True)
    # 昵称
    nickname = models.CharField(max_length=50, verbose_name="昵称", blank=True)
    # 生日
    birthdate = models.DateField(verbose_name="生日", blank=True)
    # 工作地区
    work_region = models.CharField(max_length=100, verbose_name="工作地区", blank=True)
    # 户籍地区
    household_region = models.CharField(max_length=100, verbose_name="户籍地区", blank=True)
    # 婚姻状况
    marital_status = models.CharField(max_length=10, choices=MARITAL_CHOICES, verbose_name="婚姻状况", blank=True,
                                      null=True)
    # 身高 (cm)
    height = models.PositiveIntegerField(verbose_name="身高 (cm)", blank=True)
    # 体重 (kg)
    weight = models.PositiveIntegerField(verbose_name="体重 (kg)", blank=True)
    # 学历
    education = models.CharField(max_length=10, choices=EDUCATION_CHOICES, verbose_name="学历", blank=True)
    # 月收入
    monthly_income = models.CharField(max_length=10, choices=INCOME_CHOICES, verbose_name="月收入", blank=True,
                                      null=True)
    # 职业
    occupation = models.CharField(max_length=100, verbose_name="职业", blank=True)
    # 住房情况
    housing_status = models.CharField(max_length=50, choices=HOUSING_CHOICES, verbose_name="住房情况", blank=True,
                                      null=True)
    # 购车情况
    car_status = models.CharField(max_length=50, verbose_name="购车情况", blank=True)
    # 期望结婚时间
    marriage_expectation = models.CharField(max_length=50, verbose_name="期望结婚时间", blank=True)
    # 自我介绍
    self_introduction = models.TextField(verbose_name="自我介绍", blank=True)
    # 父母帮征婚
    parental_involvement = models.CharField(max_length=50, verbose_name="父母帮征婚", blank=True)
    # 微信
    wechat = models.CharField(max_length=50, blank=True, verbose_name="微信")
    # 微信二维码
    wechat_QR = models.CharField(max_length=600, blank=True, verbose_name="微信二维码")  # 用户头像字段
    # QQ
    qq = models.CharField(max_length=50, blank=True, verbose_name="qq")
    # 父母状态
    parent_status = models.CharField(max_length=50, verbose_name="父母状态", blank=True)
    # 是否愿意与父母同住
    live_with_parents = models.CharField(max_length=50, verbose_name="是否愿意与父母同住", blank=True)
    # 吸烟情况
    smoking_status = models.CharField(max_length=50, verbose_name="吸烟情况", blank=True)
    # 嫁娶形式
    marriage_form = models.CharField(max_length=50, choices=MARRIAGE_CHOICES, verbose_name="嫁娶形式", blank=True,
                                     null=True)
    # 子女情况
    children_status = models.CharField(max_length=50, verbose_name="子女情况", blank=True)
    # 养宠物吗 格式 '鸟,狗,兔子'
    pets = models.CharField(max_length=100, choices=PET_CHOICES, verbose_name="养宠物吗", blank=True)
    # 兴趣爱好 格式 '打篮球,踢足球'
    hobbies = models.CharField(max_length=200, choices=HOBBY_CHOICES, verbose_name="兴趣爱好", blank=True)
    # 血型
    blood_type = models.CharField(max_length=10, verbose_name="血型", blank=True)
    # 民族
    ethnicity = models.CharField(max_length=10, verbose_name="民族", blank=True)
    # 毕业院校
    alma_mater = models.CharField(max_length=100, blank=True, verbose_name="毕业院校")
    # 单位类型
    employer_type = models.CharField(max_length=50, verbose_name="单位类型", blank=True)
    # 工作单位
    employer = models.CharField(max_length=100, blank=True, verbose_name="工作单位")
    # 房产位置
    property_location = models.CharField(max_length=100, blank=True, verbose_name="房产位置")
    # 位置
    location = models.CharField(max_length=600, blank=True)

    # 择偶要求
    # 年龄范围
    age_range = models.CharField(max_length=20, verbose_name="年龄范围", blank=True)
    # 身高范围
    height_range = models.CharField(max_length=20, verbose_name="身高范围", blank=True)
    # 最低学历
    minimum_education = models.CharField(max_length=10, verbose_name="最低学历", blank=True)
    # 最低收入
    minimum_income = models.CharField(max_length=10, verbose_name="最低收入", blank=True)
    # 结婚时间
    marriage_timing = models.CharField(max_length=50, verbose_name="结婚时间", blank=True)
    # 房子要求
    desired_housing_status = models.CharField(max_length=50, verbose_name="房子", blank=True)
    # 期望婚姻状况
    desired_marital_status = models.CharField(max_length=10, verbose_name="期望婚姻状况", blank=True)
    # 其他要求
    other_requirements = models.TextField(blank=True, verbose_name="其他要求")
    # 真实姓名
    realName = models.CharField(max_length=200, blank=True, verbose_name='真实姓名')
    # 身份证
    IDCode = models.CharField(max_length=18, unique=True, blank=True, verbose_name='身份证')
    # 毕业证书图片
    diplomaImage = models.CharField(max_length=600, blank=True, verbose_name="毕业证书图片")
    # 机动车行驶证图片
    carImage = models.CharField(max_length=600, blank=True, verbose_name="机动车行驶证图片")
    # 房产证图片
    houseImage = models.CharField(max_length=600, blank=True, verbose_name="房产证图片")
    # 工资流水图片
    salaryImage = models.CharField(max_length=600, blank=True, verbose_name="工资流水图片")
    # 工作经验
    work_time = models.PositiveIntegerField(verbose_name="工作经验（年）", blank=True)
    # 省
    my_province = models.CharField(max_length=20, blank=True, verbose_name="省")
    # 市
    my_city = models.CharField(max_length=20, blank=True, verbose_name="市")
    # 区
    my_area = models.CharField(max_length=20, blank=True, verbose_name="区")
    # 工作省
    work_province = models.CharField(max_length=20, blank=True, verbose_name="工作省")
    # 工作市
    work_city = models.CharField(max_length=20, blank=True, verbose_name="工作市")
    # 工作区
    work_area = models.CharField(max_length=20, blank=True, verbose_name="工作区")
    # 期望工作省
    desired_work_province = models.CharField(max_length=20, blank=True, verbose_name="期望工作省")
    # 期望工作市
    desired_work_city = models.CharField(max_length=20, blank=True, verbose_name="期望工作市")
    # 期望工作区
    desired_work_area = models.CharField(max_length=20, blank=True, verbose_name="期望工作区")
    # 是否置顶
    stick_status = models.BooleanField(default=False, verbose_name='是否置顶', blank=True)
    # 是否购买热度
    hot_status = models.BooleanField(default=False, verbose_name='是否购买热度', blank=True)


# 用户表
class User(models.Model):
    phone = models.CharField(max_length=30)  # 手机号
    id = models.CharField(max_length=100, primary_key=True)  # 用户唯一标识ID
    is_locked = models.BooleanField(default=False)  # 账号是否被锁定
    matchmaker = models.ForeignKey(to=Matchmaker, on_delete=models.DO_NOTHING, blank=True, default='none')  # 红娘外键
    userinfo = models.ForeignKey(to=UserProfile, on_delete=models.DO_NOTHING, max_length=50, blank=True,
                                 default='none')  # 用户信息外键
    commitment = models.BooleanField(default=True)  # 用户同意书
    countdown = models.DateTimeField(blank=True)  # 验证码过期时间
    code = models.CharField(max_length=6, blank=True)  # 验证码
    gold = models.ForeignKey(Gold, on_delete=models.DO_NOTHING, blank=True)


# 用户动态表
class UserBlog(models.Model):
    id = models.CharField(primary_key=True, default=uuid.uuid4, editable=False, max_length=255)  # 动态id
    content = models.TextField(max_length=600)  # 动态内容
    likes_num = models.IntegerField(default=0)  # 点赞数
    image_paths = models.JSONField(null=True)  # 动态图片
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blogs')  # 关联用户
    create_at = models.DateTimeField(auto_now_add=True)  # 发布时间


# 点赞模型
class Likes(models.Model):
    id = models.CharField(primary_key=True, default=uuid.uuid4, editable=False, max_length=255)
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='likes')
    blog = models.ForeignKey(UserBlog, on_delete=models.CASCADE, related_name='blogs')
    is_like = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)


# 礼物模型
class Gifts(models.Model):
    id = models.CharField(primary_key=True, default=uuid.uuid4, editable=False, max_length=255)  # 礼物id
    name = models.CharField(max_length=100)
    image = models.URLField(max_length=100)
    price = models.DecimalField(max_digits=10, decimal_places=2, default=10)
    video = models.CharField(max_length=100)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)


# 送礼物模型
class GiftTransaction(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, max_length=255)  # 送礼物id
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='gift_transactions')
    blog = models.ForeignKey(UserBlog, on_delete=models.CASCADE, related_name='gift_transactions')
    gift = models.ForeignKey(Gifts, on_delete=models.CASCADE, related_name='transactions')
    send_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='send_gift_transactions')
    send_at = models.DateTimeField(auto_now_add=True)


# 置顶用户表
class UserTop(models.Model):
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=50)  # 用户外键
    id = models.CharField(max_length=50, primary_key=True, )  # id


# 活动表
class Activity(models.Model):
    id = models.CharField(max_length=50, primary_key=True)  # 活动ID
    name = models.CharField(max_length=100)  # 活动名称
    describe = models.CharField(max_length=100)  # 活动描述
    place = models.CharField(max_length=100)  # 活动地点
    start_time = models.DateTimeField()  # 活动开始时间
    end_time = models.DateTimeField()  # 活动结束时间
    description = models.TextField()  # 活动详情及规则
    company = models.CharField(max_length=50)  # 主办单位
    Participating_units = models.CharField(max_length=50, blank=True)  # 参加单位
    scale = models.CharField(max_length=50, blank=True)  # 活动规模
    poster = models.CharField(max_length=100)  # 活动海报
    status = models.CharField(max_length=10)  # 状态


# 活动报名表
class Application(models.Model):
    id = models.CharField(max_length=50, primary_key=True)  # ID
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=50)  # 用户外键
    activity = models.ForeignKey(to=Activity, on_delete=models.CASCADE)  # 活动外键
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    commitment = models.BooleanField(default=True)  # 参加活动同意书


# 花费详情表
class Details(models.Model):
    id = models.CharField(max_length=50, primary_key=True, default=uuid.uuid4)
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=50)  # 用户外键
    details_in_date = models.DateField(auto_now_add=True)  # 明细日期，自动设置为记录创建的日期
    source = models.CharField(max_length=100)  # 获取金币的途径
    amount = models.PositiveIntegerField()  # 获取的金币数量


# 用户浏览记录表
class UserViewVisitor(models.Model):
    id = models.CharField(max_length=50, primary_key=True)  # ID
    viewers = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=100,
                                related_name='viewer')  # 用户外键，被观看者
    viewed = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=100, related_name='vieweds')  # 用户外键，观看者
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间


# 信息表
class MessageView(models.Model):
    id = models.CharField(max_length=100, primary_key=True)
    title = models.CharField(max_length=100, default='none')
    content = models.CharField(max_length=255, blank=True)
    time = models.DateTimeField(auto_now_add=True)
    flag = models.BooleanField(default=False)
    user = models.ForeignKey(to=User, max_length=100, on_delete=models.CASCADE)


# 签到表
class Signup(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=50)  # 用户外键
    sign_in_date = models.DateField(auto_now_add=True)  # 签到日期，自动设置为记录创建的日期


# 互换记录表
class Interchange(models.Model):
    id = models.CharField(max_length=50, primary_key=True)
    promoter = models.ForeignKey(to=User, max_length=50, on_delete=models.DO_NOTHING, related_name='promoter')
    recipient = models.ForeignKey(to=User, max_length=50, on_delete=models.DO_NOTHING, related_name='recipient')
    Initiation_time = models.DateTimeField(auto_now_add=True)
    accept = models.BooleanField(default=False)
    state = models.IntegerField(default=0)  # 0发起状态，1同意状态，2拒绝状态


# 我的关注
class UserAttentions(models.Model):
    own_user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=100, related_name='attentions_given')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, max_length=100,
                             related_name='attentions_received')  # 关联用户表外键,喜欢的用户


# 用户发布动态
class UserTweets(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    content = models.TextField()
    image_paths = models.JSONField()
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.content
